package com.bdqn.controller;

import com.bdqn.entity.Custom;
import com.bdqn.entity.DataModel;
import com.bdqn.entity.Parameters;
import com.bdqn.service.CustomManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class CustomManageController {
    @Autowired
    CustomManageService service;
    @RequestMapping(value = "CustomInfo")
    public DataModel<Custom> getCustomInfo(Parameters parameters){
        parameters.setPage((parameters.getPage()-1)*parameters.getLimit());
        DataModel<Custom> dataModel=new DataModel<>();
        dataModel.setCode(0);
        dataModel.setMsg("");
        dataModel.setCount(service.getCount(parameters));
        dataModel.setData(service.getCustomInfo(parameters));
        return dataModel;
    }
    @RequestMapping(value = "addCustom")
    public int addCustom(Custom custom){
        if(custom.getId()!=null) return service.updateCustom(custom);
        return service.addCustom(custom);
    }


    @RequestMapping(value = "updateCustom")
    public int updateCustom(Custom custom){
        return service.updateCustom(custom);
    }
    @RequestMapping(value = "delCustom")
    public int delCustom(int id){
        return service.delCustom(id);
    }

    @RequestMapping(value = "getCustom")
    public List<Custom> getCustom(){
        return service.getCustom();
    }

}
